var InteractiveRow = EventDispatcher.extend({

    DELETE_ACTION: 'delete',

    _container: null,
    _rowId: null,
    _ajaxHandlerUrl: null,
    _infoRow: null,
    _formRow: null,

    constructor: function(container)
    {
        this._container = $(container);
        this._rowId = this._container.find('input[name="id"]').val();
        this._infoRow = this._container.find('.info_row');
        this._formRow = this._container.find('.form_row');
        this._ajaxHandlerUrl = this._formRow.attr('action');


        var deleteButton = this._container.find('.delete_button');
        var editButton = this._container.find('.edit_button');
        var cancelButton = this._container.find('.cancel_button');

        deleteButton.bind('click', handler(this, '_onDeleteButtonClick'));
        editButton.bind('click', handler(this, '_onEditButtonClick'));
        cancelButton.bind('click', handler(this, '_onCancelButtonClick'));
    },

    _onEditButtonClick: function(evt)
    {
        this._infoRow.hide();
        this._formRow.show();
    },

    _onCancelButtonClick: function(evt)
    {
        this._formRow.hide();
        this._infoRow.show();
    },

    _onDeleteButtonClick: function(evt)
    {
        if (confirm("Вы точно хотите удалить эту запись?"))
        {
            var data = {
                id: this._rowId,
                action: this.DELETE_ACTION
            };
            this._sendAjaxRequest(data);
        }
    },

    _sendAjaxRequest: function(ajaxData)
    {
        $.ajax({
            type: 'post',
            url: this._ajaxHandlerUrl,
            data: ajaxData,
            dataType: 'json',
            success: handler(this, '_onAjaxSuccess')
        });
    },

    _onAjaxSuccess: function(resp)
    {
        this.dispatchEvent(FormRow.AJAX_SUCCESS_EVENT, resp);
    }
});